package com.wlw.layoutmanager.adapters;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wlw.layoutmanager.R;
import com.wlw.layoutmanager.activity.SkidRight2Activity;
import com.wlw.layoutmanager.beans.SkidRightBean;

import java.util.List;

public class SkidRightAdapter extends BaseAdapter<SkidRightBean> {
    public SkidRightAdapter(List<SkidRightBean> data) {
        this(R.layout.item_skid_right, data);
    }

    public SkidRightAdapter(int layoutResId, List<SkidRightBean> data) {
        super(layoutResId, data);
    }

    @Override
    public void onBindView(BaseViewHolder holder, SkidRightBean skidRightBean, int position) {
        ImageView img = (ImageView) holder.getView(R.id.img_bg);
        Glide.with(holder.itemView.getContext()).asGif().load(skidRightBean.getResId()).into(img);
        TextView title = (TextView) holder.getView(R.id.tv_title);
        TextView bottom = (TextView) holder.getView(R.id.tv_bottom);
        title.setText(skidRightBean.getTitles());
        img.setOnClickListener(it -> {
            Intent intent = new Intent(holder.itemView.getContext(), SkidRight2Activity.class);
            intent.putExtra("img", skidRightBean.getResId());
            intent.putExtra("title", skidRightBean.getTitles());
            Pair<View, String> p1 = Pair.create(img, "img_view");
            Pair<View, String> p2 = Pair.create(title, "title");
            Pair<View, String> p3 = Pair.create(bottom, "bottom");
            ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) holder.itemView.getContext(), p1, p2, p3);
            holder.itemView.getContext().startActivity(intent, optionsCompat.toBundle());
        });
    }
}
